package com.xyw.his00.controller;

import com.alipay.api.domain.PageInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xyw.his00.mapper.DrugInfoMapper;
import com.xyw.his00.pojo.dbpojo.DrugInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/druginfo/")
public class DrugInfoController {
    @Autowired
    private DrugInfoMapper drugInfoMapper;


    // 分页查询获得药品信息
  @RequestMapping("getDrugInfo")
  public IPage<DrugInfo> getDrugInfo(@RequestParam(defaultValue = "1") int pageNum,
                                     @RequestParam(defaultValue = "10") int pageSize) {
      // 创建分页对象
      Page<DrugInfo> page = new Page<>(pageNum, pageSize);

      // 执行分页查询
      IPage<DrugInfo> drugInfoPage = drugInfoMapper.selectPage(page, null); // 第二个参数为查询条件，null表示无条件

      // 返回分页信息
      return drugInfoPage;
  }
  @RequestMapping("getDrugInfoByCodeOrName")
    public List<DrugInfo> getDrugInfoByCodeOrName(@RequestParam(required = false) String drugName,
                                                  @RequestParam(required = false) String mnemonicCode) {
      QueryWrapper<DrugInfo> drugInfoQueryWrapper = new QueryWrapper<>();
      if (drugName == null | mnemonicCode == null) {
          drugInfoQueryWrapper.like("drug_name", drugName).or().like("mnemonic_code", mnemonicCode);
      }else {
          drugInfoQueryWrapper.like("drug_name", drugName).like("mnemonic_code", mnemonicCode);
      }
      return drugInfoMapper.selectList(drugInfoQueryWrapper);
  }
}
